package com.gyc.simple.common.util;

import org.apache.commons.lang.StringUtils;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @program: Inaction
 * @description: 时间处理工具类
 * @author: Mr.gyc
 * @create: 2019-08-01 11:00
 */
public class DateUtils {

    public static String getLocalDateTimeToString(LocalDateTime localDateTime,String format){
        return localDateTime.format(DateTimeFormatter.ofPattern(format));
    }

    public static String dateToString(Date date,String format){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if(date!=null){
            if(StringUtils.isNotBlank(format)){
                dateFormat.applyPattern(format);
                try {
                    return dateFormat.format(date);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        throw new NullPointerException();
    }



    public static Timestamp getTimestamp(Date date) {
        return new Timestamp(date.getTime());
    }
}
